class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    SetCriterion(item) {
        // 设置检索条件
        item['ApYear'] = $("#ApYear").val();

        return item;
    }
    GetFilter() {
        let item = super.GetFilter(0);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    EmptyTableContent() {
        $("#tab_data01 tbody").empty();
    }
    SetTableContent(result) {
        $("#tab_data01 tbody").empty();

        let content_01 = '';
        this.rows = result.length;
        for (let i = 0; i < result.length; i++) {
            content_01 += '<tr>';
            content_01 += '<td style="text-align:center;">' + (i + 1) + '</td>';
            content_01 += '<td style="text-align:center;">' + formatNullData(result[i].startDate) + '</td>';
            content_01 += '<td style="text-align:center; border-right:none;">' + formatNullData(result[i].endDate) + '</td>';
            content_01 += '</tr>';
            $("#tab_data01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tab_data01");
        $(window).resize();                     // 防止因为出现滚动条而造成画面显示问题
        $('#loading').hide();
    }
    DoInsert() {
        showModal(600, 308, '会计期参数设置', parent.basePath + '/financial/accouting_period/options.html', null, null);
    }
    DoDelete() {
        let _params = {};
        // 设置条件
        _params['ApYear'] = $("#ApYear").val();
        _params['DeletedBy'] = $("#UserId").val();
        
        super.DoDelete(_params, function (_this, data) {
            if (data.Success === true) {
                _this.EmptyTableContent();
                ShowSuccessMessagePanel("删除成功。");
            } else {
                ShowErrorMessagePanel("删除不成功。");
            }
        });
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#search_btn").hide(); // 无需搜索，隐藏搜索按钮
    // 初始化今年为当前会计年度
    let _currentDate = new Date();
    $("#ApYear").val(_currentDate.getFullYear());

    _Instance = new MyPage(0, null, null, null, null, null, null, null,
            "/financial/accouting_period/fetchByApYear.html",
            "/financial/accouting_period/delete.html");

    $('#SpinnerApYear span:last-child').on('click', function (event) {
        $('#ApYear').val(parseInt($('#ApYear').val(), 10) + 1);
        _Instance.OnPageLoad();
        event.stopPropagation();
    });
    $('#SpinnerApYear span:first').on('click', function (event) {
        $('#ApYear').val(parseInt($('#ApYear').val(), 10) - 1);
        _Instance.OnPageLoad();
        event.stopPropagation();
    });
    _Instance.OnPageLoad();
}

function onPageResize() {
}
